package vn.gq.udv.utils;


import vn.gq.udv.template.GQApplication;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePreferenceUtil {
	
	private static SharePreferenceUtil instance;
	private SharedPreferences pref;
	
	public SharePreferenceUtil(Context context) {
		pref = context.getSharedPreferences(GQApplication.getContext().getPackageName(), Context.MODE_PRIVATE);
	}
	
	public void putString(String key, String value) {
		Editor editor = pref.edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public void putBoolean(String key, boolean value) {
		Editor editor = pref.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}
	
	public void putInt(String key, int value) {
		Editor editor = pref.edit();
		editor.putInt(key, value);
		editor.commit();
	}
	
	public void putFloat(String key, float value) {
		Editor editor = pref.edit();
		editor.putFloat(key, value);
		editor.commit();
	}
	
	public void putLong(String key, long value) {
		Editor editor = pref.edit();
		editor.putLong(key, value);
		editor.commit();
	}
	
	public String getString(String key, String defValue) {
		return pref.getString(key, defValue);
	}
	
	public boolean getBoolean(String key, boolean defValue) {
		return pref.getBoolean(key, defValue);
	}
	
	public int getInt(String key, int defValue) {
		return pref.getInt(key, defValue);
	}
	
	public float getFloat(String key, float defValue) {
		return pref.getFloat(key, defValue);
	}
	
	public float getLong(String key, long defValue) {
		return pref.getLong(key, defValue);
	}
	
	public static SharePreferenceUtil getInstance(Context context) {
		if (instance == null) {
			instance = new SharePreferenceUtil(context);
		}
		return instance;
	}
}
